package v1

import (
	"bc/service"
	"bc/util"
	"crypto/md5"
	"encoding/hex"
	"github.com/gin-gonic/gin"
)

func GetAuth(c *gin.Context){

	md5Pwd := md5.New()
	md5Pwd.Write([]byte(util.Config.App.Salt + c.PostForm("password")))
	pwd := hex.EncodeToString(md5Pwd.Sum(nil))

	token,uid := service.User.Auth(map[string]interface{}{
		"username":c.PostForm("username"),
		"password":pwd,
	})
	c.Set("uid",uid)
	if token != ""{
		LogAdd(c,"登录系统", "登录登出")
		c.JSON(200,gin.H{
			"code":200,
			"token":token,
		})
		return
	}
	c.JSON(200,gin.H{
		"code":500,
		"token":"",
		"msg":"帐号或密码错误",
	})

}
